<template>
  <view class="meeting-scoring">
    <uni-forms :modelValue="formState" ref="form" :rules="rules">
      <cu-cell-group>
        <uni-forms-item name="handleContent">
          <cu-cell title="领导讲话" required column>
            <textarea
              v-model="formState.handleContent"
              class="text-area"
              placeholder="请输入"
              :maxlength="1000"
              style="height: 300rpx"
            />
          </cu-cell>
        </uni-forms-item>
      </cu-cell-group>
    </uni-forms>
    <view class="submit" @click="handleSubmit">确定</view>
  </view>
</template>
<script>
import { doSpeak } from '@/api/duty-basic/duty-meeting'
import CuCell from '@/components/cu-cell/cu-cell.vue'
import CuCellGroup from '@/components/cu-cell/cu-cell-group.vue'
export default {
  data() {
    return {
      formState: {
        handleContent: ''
      },
      procTaskId: '',
      meetingId: '',
      rules: {
        handleContent: {
          rules: [
            {
              required: true,
              errorMessage: '必填项不能为空'
            }
          ]
        }
      }
    }
  },
  components: { CuCell, CuCellGroup },
  methods: {
    async handleSubmit() {
      await this.$refs.form.validate()
      uni.showModal({
        content: '提交后，填写的内容将不可以修改，请确定填写无误后再提交',
        confirmText: '确定',
        success: async (res) => {
          if (res.confirm) {
            await doSpeak({
              meetingId: this.meetingId,
              procTaskId: this.procTaskId,
              handleContent: this.formState.handleContent
            })
            uni.showToast({
              title: '提交成功！',
              icon: 'success',
              duration: 2000,
              success() {
                uni.navigateBack()
              }
            })
          }
        }
      })
    }
  },
  onReady() {
    // 需要在onReady中设置规则
    this.$refs.form.setRules(this.rules)
  },
  onLoad({ procTaskId, id }) {
    this.meetingId = id
    this.procTaskId = procTaskId
  }
}
</script>
<style scoped lang="scss">
.meeting-scoring {
  background: rgb(245, 245, 245);
  margin-top: 30rpx;
  .submit {
    width: 600rpx;
    height: 88rpx;
    background: #454a5e;
    border-radius: 50rpx 50rpx 50rpx 50rpx;
    opacity: 1;
    text-align: center;
    line-height: 88rpx;
    font-size: 36rpx;
    font-weight: 400;
    color: #ffffff;
    margin: 0 auto;
    margin-top: 70rpx;
    margin-bottom: 70rpx;
  }
  .text-area {
    height: 130rpx;
  }
}
</style>
